package com.zenithmind.news.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zenithmind.news.pojo.entity.UserSubscription;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 用户订阅Mapper接口
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Mapper
public interface UserSubscriptionMapper extends BaseMapper<UserSubscription> {

    /**
     * 查询用户订阅列表
     * 
     * @param userId 用户ID
     * @param type 订阅类型
     * @param status 订阅状态
     * @return 订阅列表
     */
    List<UserSubscription> selectUserSubscriptions(@Param("userId") String userId,
                                                   @Param("type") Integer type,
                                                   @Param("status") Integer status);

    /**
     * 查询订阅了指定目标的用户列表
     * 
     * @param type 订阅类型
     * @param target 订阅目标
     * @param enablePush 是否启用推送
     * @return 用户ID列表
     */
    List<String> selectSubscribedUsers(@Param("type") Integer type,
                                      @Param("target") String target,
                                      @Param("enablePush") Integer enablePush);

    /**
     * 查询用户的推送偏好
     * 
     * @param userId 用户ID
     * @return 推送偏好列表
     */
    List<UserPushPreference> selectUserPushPreferences(@Param("userId") String userId);

    /**
     * 批量更新订阅状态
     * 
     * @param userId 用户ID
     * @param targets 订阅目标列表
     * @param status 订阅状态
     * @return 更新行数
     */
    int batchUpdateStatus(@Param("userId") String userId,
                         @Param("targets") List<String> targets,
                         @Param("status") Integer status);

    /**
     * 查询热门订阅
     * 
     * @param type 订阅类型
     * @param limit 限制数量
     * @return 热门订阅列表
     */
    List<PopularSubscription> selectPopularSubscriptions(@Param("type") Integer type,
                                                         @Param("limit") Integer limit);

    /**
     * 用户推送偏好
     */
    class UserPushPreference {
        private String userId;
        private Integer type;
        private String target;
        private String targetName;
        private String pushMethods;
        private Integer pushFrequency;
        private String pushTimeRange;
        private Integer priority;
        private Double weight;

        // Getters and Setters
        public String getUserId() { return userId; }
        public void setUserId(String userId) { this.userId = userId; }
        
        public Integer getType() { return type; }
        public void setType(Integer type) { this.type = type; }
        
        public String getTarget() { return target; }
        public void setTarget(String target) { this.target = target; }
        
        public String getTargetName() { return targetName; }
        public void setTargetName(String targetName) { this.targetName = targetName; }
        
        public String getPushMethods() { return pushMethods; }
        public void setPushMethods(String pushMethods) { this.pushMethods = pushMethods; }
        
        public Integer getPushFrequency() { return pushFrequency; }
        public void setPushFrequency(Integer pushFrequency) { this.pushFrequency = pushFrequency; }
        
        public String getPushTimeRange() { return pushTimeRange; }
        public void setPushTimeRange(String pushTimeRange) { this.pushTimeRange = pushTimeRange; }
        
        public Integer getPriority() { return priority; }
        public void setPriority(Integer priority) { this.priority = priority; }
        
        public Double getWeight() { return weight; }
        public void setWeight(Double weight) { this.weight = weight; }
    }

    /**
     * 热门订阅
     */
    class PopularSubscription {
        private String target;
        private String targetName;
        private Long subscribeCount;
        private Double score;

        // Getters and Setters
        public String getTarget() { return target; }
        public void setTarget(String target) { this.target = target; }
        
        public String getTargetName() { return targetName; }
        public void setTargetName(String targetName) { this.targetName = targetName; }
        
        public Long getSubscribeCount() { return subscribeCount; }
        public void setSubscribeCount(Long subscribeCount) { this.subscribeCount = subscribeCount; }
        
        public Double getScore() { return score; }
        public void setScore(Double score) { this.score = score; }
    }
}
